package com.axjy.his.controller;

import com.axjy.his.controller.vo.Node;
import com.axjy.his.service.PermissionService;
import com.axjy.his.utils.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lenovo on 2017/11/10.
 */
@RestController
@RequestMapping("/sys/permission")
public class PermissionController {

    @Resource
    private PermissionService per;

    @GetMapping("/getTree")
    public List<Node> getTree(Integer roleId){
        List<Node> list=per.searchNodes4Tree(roleId);
        return list;
    }

    public String msg;

    @PostMapping("/grant")
    public String grant(Integer roleId,Integer[] ids){
        try{
            per.grant(roleId,ids);
            msg="角色授权成功！";
        }catch(Exception ex){
            msg="角色授权失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
}
